<template>
  <div v-popover:avatar class="right-menu-item">
    <div class="avatar-wrapper">
      <img v-if="avatar" class="user-avatar" :src="avatar" />
      <el-popover
        ref="avatar"
        trigger="click"
        placement="bottom"
        :visible-arrow="false"
        popper-class="toolbar-popover"
      >
        <span
          slot="reference"
          class="user-avatar"
          :style="{ background: color }"
          >{{ avatarName }}</span
        >
        <div class="avatar-select">
          <div class="avatar-select-title">个人配置</div>
          <ul class="avatar-select-options" style="list-style：none；">
            <li @click="goPersonalCenter">
              <span>个人信息</span>
            </li>
            <li @click="loginOut">
              <span>退出</span>
            </li>
          </ul>
        </div>
      </el-popover>
    </div>
  </div>
</template>

<script>
import { avatar, avatarName, avatarColor } from './avatar'
// import { USER } from '@/store/State/stateTypes'
// import { mapState } from 'vuex'
// import * as stateTypes from '@/store/State/stateTypes'
// import { loginOut } from '@/api/app'
export default {
  name: 'Avatar',
  computed: {
    data() {
      return {
        userFullname: '高飞明'
      }
    },
    avatar,
    avatarName,
    color() {
      let color = avatarColor.male
      if (this.data.sex != '男') {
        color = avatarColor.female
      }
      return color[Math.floor(Math.random() * 10)]
    }
    // ...mapState([stateTypes.INTERFACE_CONFIG])
  },
  methods: {
    async goPersonalCenter() {
      await this.$store.dispatch(
        '/views/manage/account/personalinfo/personalinfo'
      )
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    },
    async loginOut() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.right-menu-item {
  display: inline-block;
  width: 36px;
  height: 100%;
  margin: 0 10px;
  line-height: 50px;
  text-align: center;
  vertical-align: middle;
  color: black;
  cursor: pointer;

  &:hover {
    background: rgba(0, 0, 0, 0.05);
    cursor: pointer;
  }
}
.avatar-wrapper {
  position: relative;
  margin-right: 3px;
  cursor: pointer;

  .user-avatar {
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 14px;
    line-height: 24px;
    vertical-align: middle;
    color: #fff;
    background: #b9b9b9;
  }
}

.avatar-select {
  list-style-type: none;
  list-style: none;
  &-title {
    padding: 0 0 8px;
    border-bottom: 1px solid #f2f3f4;
    font-weight: bold;
    text-align: center;
    color: #393e45;
  }

  &-options {
    list-style-type: none;
    padding: 0;
    margin: 0px;
    list-style: none;
    padding-top: 8px;
    text-align: center;

    li {
      padding: 4px 0;
      font-size: 0;
      cursor: pointer;

      &:hover {
        background-color: #f7f8f8;
      }
    }

    .avatar-icon {
      margin-right: 10px;
      font-size: 0;
      color: #999;
    }

    span {
      font-size: 14px;
      vertical-align: middle;
      color: #999;
    }
  }
}
</style>